<?php
	class loaikyhandb
	{
		public function Them($TenLoaiKyHan = "", $KyHan = "")
		{
			$sql = "INSERT INTO loaikyhan(TenLoaiKyHan, KyHan)
						   VALUES('$TenLoaiKyHan', '$KyHan')";
			
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function CapNhat($MaLoaiKyHan = 0, $TenLoaiKyHan = "", $KyHan = "")
		{
			$sql = "UPDATE loaikyhan 
					SET TenLoaiKyHan = '$TenLoaiKyHan',
						KyHan = '$KyHan'
					WHERE MaLoaiKyHan = $MaLoaiKyHan";
			
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function TonTaiTrongLaiSuatGui($MaLoaiKyHan = 0)
		{
			$sql = "SELECT * FROM laisuatgui WHERE 1";
			if($MaLoaiKyHan > 0)
				$sql.= " AND MaLoaiKyHan = $MaLoaiKyHan";
				
			$data = new dataservice();
			return $data->ExecuteQuery($sql);
		}
		
		public function Xoa($MaLoaiKyHan = 0)
		{
			$sql = "DELETE FROM loaikyhan 
					WHERE MaLoaiKyHan = $MaLoaiKyHan";
			
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function XoaTatCa()
		{
			$sql = "DELETE FROM loaikyhan";			
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function LayDanhSach($MaLoaiKyHan = 0, $TenLoaiKyHan = "", $KyHan = "")
		{
			$sql = "SELECT * 
					FROM loaikyhan 
					WHERE 1";
			
			if($MaLoaiKyHan > 0)
				$sql .= " AND MaLoaiKyHan = $MaLoaiKyHan";
				
			if($TenLoaiKyHan != "")
				$sql .= " AND TenLoaiKyHan = '$TenLoaiKyHan'";
			
			if($KyHan != "")
				$sql .= " AND KyHan = '$KyHan'";		
			
			$data = new dataservice();
			return $data->ExecuteQuery($sql);
		}
	}
?>